#include <iostream>
#include <vector>
#include <queue>
#include <cstdio>

const int N = 1e5 + 5;

int n;
std::vector<int> adj[N];
std::priority_queue<std::pair<int, int>> pq[N];
int f[N], g[N], siz[N];

inline void dfs(int u, int fa) {
	siz[u] = 1;
	for(int v : adj[u]) if(v != fa) {
		dfs(v, u);
		siz[u] += siz[v];
		if(pq[u].size() < pq[v].size()) swap(pq[u], pq[v]);
		while(!pq[v].empty()) pq[u].push(pq[v].top()), pq[v].pop();
	}
	if(pq[u].empty()) {
		pq[u].emplace(1, 0);
	} else if(pq[u].size() == 1) {
		auto e = pq[u].top(); pq[u].pop();
		pq[u].emplace(e.first, e.second + 1);
		pq[u].emplace(1, -1);
	} else {
		auto x = pq[u].top(); pq[u].pop();
		auto y = pq[u].top(); pq[u].pop();
		pq[u].emplace(x.first + y.first + 1, x.second + y.second);
	}
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);

	std::freopen("bird.in", "r", stdin);
	std::freopen("bird.out", "w", stdout);

	std::cin >> n;
	for(int i = 2; i <= n; ++i) {
		int u, v; std::cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs(1, 0);
	std::cout << pq[1].top().first + (!!pq[1].top().second) << "\n";

	return 0;
}
